﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>判断文本框是否为空</title>
    <script>
        function validate() {
            let _txtNameObj = document.all.txtName;
            let  _txtNameValue = _txtNameObj.value;
            if ((_txtNameValue === null) || (_txtNameValue.length < 1)) {
                window.alert("文本框内容为空，请输入内容");
                _txtNameObj.focus();
                return;
            }
        }
    </script>
</head>
<body>
    <form method="post" action="#">
        <input type="text" name="txtName" />
        <input type="button" value="确定" onclick="validate()" />
    </form>
</body>
</html>